package com.lianbang.staff.module.main

import android.os.Bundle
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentStatePagerAdapter
import cn.ubest.mvvmcore.base.BaseFragment
import cn.ubest.mvvmcore.utils.ResourcesUtils
import cn.ubest.mvvmcore.utils.SpanUtils
import com.gyf.barlibrary.ImmersionBar
import com.lianbang.staff.R
import com.lianbang.staff.databinding.FragmentOrderBinding
import com.lianbang.staff.vm.OrderVM
import kotlinx.android.synthetic.main.fragment_order.*

/**
 * Created by maoqi on 2020/12/28.
 */
class OrderFragment : BaseFragment<OrderVM, FragmentOrderBinding>() {

    companion object {
        const val ORDER_ADDED = 0
        const val ORDER_HANDLED = 1
        const val ORDER_RETURN = -1
        const val ORDER_FINISHED = 3
        fun newInstance(): OrderFragment {
            return OrderFragment()
        }
    }

    override fun initLayout(): Int {
        return R.layout.fragment_order
    }

    override fun initStatusBar() {
        ImmersionBar.with(this)
            .statusBarView(view_status_bar)
            .init();
    }

    override fun initData(arguments: Bundle?) {

    }

    override fun initView(view: View) {
        tv_order_today.text =
            SpanUtils().append("5")
                .setFontSize(ResourcesUtils.getDimens(R.dimen.sp_26))
                .setBold()
                .append("个名门下单")
                .create()
        tv_order_running_water.text = "15000"
        val titleList = mutableListOf("新增订单", "已处理", "退货/售后", "已完成")
        val fragmentList = mutableListOf(
            OrderChildListFragment.newInstance(ORDER_ADDED),
            OrderChildListFragment.newInstance(ORDER_HANDLED),
            OrderChildListFragment.newInstance(ORDER_RETURN),
            OrderChildListFragment.newInstance(ORDER_FINISHED)
        )

        tl_tab.setupWithViewPager(vp_pager)
        vp_pager.adapter = object : FragmentStatePagerAdapter(
            childFragmentManager,
            FragmentStatePagerAdapter.BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT
        ) {
            override fun getPageTitle(position: Int): CharSequence? {
                return titleList[position]
            }

            override fun getItem(position: Int): Fragment {
                return fragmentList[position]
            }

            override fun getCount(): Int {
                return fragmentList.size
            }
        }
    }

    override fun loadData() {
    }

}